<?php
session_start();
cls_General_Forms::code_block_starts('');

//echo 'this is the content of the center';
 #########################################################################  
$blocked = security::head_entry();
  if($blocked){      
  #Form to be loaded in case no post or request has been made		
    if((!isset($_POST['submit']) || !isset($_REQUEST)) && !isset($_SESSION['username'])){
       cls_General_Forms::login_form();  
        #get all the users for display
        
                      // $user_type=admin_functions::get_users();
                       #display the adding form
                      // admin_forms::add_user($user_type);
                     
        }else{
           // echo "<center style='font-size:24pt';>Welcome to SSC Student Information System</center>";
        }
  }else{
      die("<p class='warnings'>This address is temporarily closed due to successive failed login attempts</p>");
  }
#this will be the processing part of posts and requests
if(isset($_POST['submit'])){
    switch($_POST['submit']){

      
            
            case 'LOGIN':
                    #this will check validity of credentials if  true
                    $profile=admin_functions::check_user_profile($_POST['username'],$_POST['password'],$_POST['profile_id']);  
                        if($profile){                               
                              #this will reset the counter of the ip
                              $_SESSION['page']="Home";  
                              header('location:main.php');
                        }else{
                            die("<p class='warnings'>Invalid user credentials!</p>");
                        }           
                            
                
                break;       
                
     
            
            case 'Add User':
                #add a user
                admin_functions::add_edit_delete_users($_POST,"add");
                break;
            
             case 'Update User':
                #add a user
                admin_functions::add_edit_delete_users($_POST,"edit");
                break;  
                  
              case 'Apply Configuration':               
                #this function inserts data to config_assessment  
                admin_functions::enable_assessment($_POST,$_POST['semester']); 
                echo "YOU have successfully configured this system";
                break;
                       
            
                
                case 'Apply Settings': 
                    #this function will override default settings for syear
                        admin_functions::setting_configure($_POST); 
                    break;  
                                               
    }           
}
if(isset($_REQUEST['action']) && isset($_SESSION['username'])){
    switch($_REQUEST['action']){
          case 'logout':
           // admin_functions::log_out($_SESSION['username'],$_SESSION['password']);
           admin_functions::log_out($_SESSION['username'],$_SESSION['password']);
            session_destroy();
            header("location:main.php");
            break;
            
           case 'settings':
             #this will enable default settings to be changed
               $syear = miscellaneous::school_year();
               admin_forms::settings_config($syear);
                break;
           
           case 'ask':
               if($_REQUEST['page']=="admin"){
                    if($_REQUEST['spec']=="add"){
                       #get all the users for display
                       $user_type=admin_functions::get_users();
                       #display the adding form
                       admin_forms::add_user($user_type);
                   }elseif($_REQUEST['spec']=="view"){
                        #get all the data to view
                       $data=admin_functions::get_users_profile();
                        admin_forms::view($data);
                   }elseif($_REQUEST['spec']=="delete"){
                       #this will delete the user from user_profile
                       $data=array('username'=>$_REQUEST['username']);
                       admin_functions::add_edit_delete_users($data,"delete");
                   }else{
                       #this will edit the user from user_profile
                       #get all the users for display
                       $user_type=admin_functions::get_users();
                       #get records
                       $records=admin_functions::get_specific_profile($_SESSION['username']);
                       #display the adding form
                       admin_forms::edit_user($user_type,$records);
                   }
               }
               
               break;
               
          case 'config':
                 if($_REQUEST['page']=="registrar"){
                     
                 }elseif($_REQUEST['page']=="admin"){
                        if($_REQUEST['spec']=="assessment"){
                               #get the assessemtn for option
                               $assessment=admin_functions::get_assessment();
                               #show to forms
                               admin_forms::assessment_names($assessment); 
                        }
                 }
            break;
                     
    }  

}
 ###############################################################################       
cls_General_Forms::code_block_ends();
?>